<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加密货币交易模拟器 - 仪表板</title>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .price-input {
            padding: 8px;
            margin: 5px;
            border: 1px solid #ddd;
            border-radius: 4px;
            width: 200px;
            text-align: left;
        }
        select {
           padding: 8px; 
           border: 1px solid #ddd; 
           border-radius: 4px;
        }
        /* 交易表单样式 */
        .trade-form {
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        
        .form-group {
            display: flex;
            flex-direction: column;
            gap: 5px;
        }
        
        .form-group label {
            font-weight: 500;
            color: #555;
        }
        
        .form-group select,
        .form-group input {
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
            background-color: white;
        }
        
        .form-group select:focus,
        .form-group input:focus {
            outline: none;
            border-color: #007bff;
            box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
        }
        
        .trade-buttons {
            display: flex;
            gap: 10px;
            margin-top: 10px;
        }
        
        .btn-buy {
            background-color: #28a745;
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 5px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            flex: 1;
            transition: background-color 0.3s;
        }
        
        .btn-buy:hover {
            background-color: #218838;
        }
        
        .btn-sell {
            background-color: #dc3545;
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 5px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            flex: 1;
            transition: background-color 0.3s;
        }
        
        .btn-sell:hover {
            background-color: #c82333;
        }
        
        .trade-result {
            margin-top: 10px;
            padding: 15px;
            border-radius: 5px;
            text-align: center;
            font-size: 14px;
            min-height: 20px;
        }
        
        .trade-result.success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .trade-result.error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 20px;
            text-align: center;
        }
        .card {
            background: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .chart-container {
            position: relative;
            height: 400px;
            margin-bottom: 20px;
        }
        .grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
        }
        .btn {
            background: #667eea;
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 5px;
            cursor: pointer;
            margin: 5px;
        }
        .btn:hover {
            background: #5a6fd8;
        }
        .info-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 10px;
        }
        .info-item {
            padding: 10px;
            background: #f8f9fa;
            border-radius: 5px;
        }
        .currency-card {
            background: white;
            border-radius: 10px;
            padding: 15px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            border-left: 5px solid #4CAF50;
            margin-bottom: 20px;
        }
        .positive {
            color: #4CAF50;
        }
        .negative {
            color: #f44336;
        }
        .trade-history {
            max-height: 400px;
            overflow-y: auto;
        }
        .trade-item {
            padding: 10px;
            border-bottom: 1px solid #eee;
        }
        .trade-item:last-child {
            border-bottom: none;
        }
        .nav-links {
            text-align: center;
            margin: 20px 0;
        }
        .nav-links a {
            color: #667eea;
            text-decoration: none;
            margin: 0 10px;
            padding: 10px 15px;
            border-radius: 5px;
            background: white;
        }
        .nav-links a:hover {
            background: #f8f9fa;
        }
        .price-display {
            margin-top: 10px;
            padding: 10px;
            background: #e9ecef;
            border-radius: 5px;
            text-align: center;
            font-weight: bold;
        }
        .market-table {
            width: 100%;
            border-collapse: collapse;
        }
        .market-table th,
        .market-table td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        .market-table th {
            background-color: #f8f9fa;
            font-weight: bold;
        }
        .market-table tr:hover {
            background-color: #f5f5f5;
        }
        .market-table .positive {
            color: #4CAF50;
            font-weight: bold;
        }
        .market-table .negative {
            color: #f44336;
            font-weight: bold;
        }
        
        /* Markdown渲染样式 */
        .markdown-content {
            line-height: inherit;
            font-size: 12px;
        }
        
        .markdown-content h1 {
            font-size: 24px;
            margin: 5px 0 10px 0;
            color: #333;
            border-bottom: 2px solid #667eea;
            padding-bottom: 5px;
        }
        
        .markdown-content h2 {
            font-size: 20px;
            margin: 5px 0 9px 0;
            color: #444;
            border-bottom: 1px solid #ccc;
            padding-bottom: 3px;
        }
        
        .markdown-content h3 {
            font-size: 18px;
            margin: 5px 0 8px 0;
            color: #555;
        }
        
        .markdown-content h4 {
            font-size: 16px;
            margin: 5px 0 7px 0;
            color: #666;
        }
        
        .markdown-content h5 {
            font-size: 15px;
            margin: 5px 0 6px 0;
            color: #777;
        }
        .markdown-content br {
            display:none;
        }
        .markdown-content p {
            margin: 5px 0;
            text-align: justify;
        }
        
        .markdown-content strong {
            font-weight: bold;
            color: #333;
        }
        
        .markdown-content em {
            font-style: italic;
        }
        
        .markdown-content ul, .markdown-content ol {
            margin: 10px 0;
            padding-left: 20px;
        }
        
        .markdown-content li {
            margin: 5px 0;
        }
        
        .markdown-content code {
            background-color: #f4f4f4;
            padding: 2px 4px;
            border-radius: 3px;
            font-family: 'Courier New', monospace;
            font-size: 13px;
        }
        
        .markdown-content pre {
            background-color: #f8f8f8;
            border: 1px solid #ddd;
            border-radius: 5px;
            padding: 10px;
            overflow-x: auto;
            margin: 10px 0;
        }
        
        .markdown-content pre code {
            background-color: transparent;
            padding: 0;
        }
        
        .markdown-content a {
            color: #667eea;
            text-decoration: none;
        }
        
        .markdown-content a:hover {
            text-decoration: underline;
        }
        
        .markdown-content blockquote {
            border-left: 4px solid #667eea;
            padding: 0 15px;
            margin: 10px 0;
            color: #666;
        }
        
        .symbol-btn {
            background: #e9ecef;
            border: none;
            padding: 5px 10px;
            border-radius: 3px;
            cursor: pointer;
            margin: 0 2px;
        }
        .symbol-btn:hover {
            background: #dee2e6;
        }
        .popular-symbols {
            margin-top: 10px;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            gap: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>DeepSeek AI 驱动的加密货币交易模拟器</h1>
            <p>实时市场数据与AI交易策略分析</p>
        </div>
        <!-- <div class="nav-links">
            <a href="/">加密货币交易模拟器</a>
        </div> -->

        <div class="card" style="display: none;">
            <h3>实时价格查询</h3>
            <div>
                <div>
                <input type="text" id="symbolInput" class="price-input" style="text-align: left;" placeholder="请输入币种符号，如：DOGEUSDT" value="DOGEUSDT">
                 <button class="btn" onclick="getCurrentPrice()">获取当前价格</button>
                <span class="popular-symbols">
                    <span>热门币种:</span>
                    <button class="symbol-btn" onclick="setSymbol('BTCUSDT')">BTC</button>
                    <button class="symbol-btn" onclick="setSymbol('ETHUSDT')">ETH</button>
                    <button class="symbol-btn" onclick="setSymbol('BNBUSDT')">BNB</button>
                    <button class="symbol-btn" onclick="setSymbol('XRPUSDT')">XRP</button>
                    <button class="symbol-btn" onclick="setSymbol('DOGEUSDT')">DOGE</button>
                </span>  
               </div>
               
                <div id="priceResult" class="price-display"></div>
                
            </div>
        </div>

        <div class="card">
            <h3>账户概览  <span style="float: right;">  <strong>AI余额(CNY):</strong> <span id="aiBalance">-</span></span></h3>
            <div class="info-grid" id="accountOverview">
                <div class="info-item">
                    <strong>账户余额:</strong> <span id="accountBalance">-</span>
                </div>
                <div class="info-item">
                    <strong>账户总价值:</strong> <span id="accountValue">-</span>
                </div>
                <div class="info-item">
                    <strong>持仓币种:</strong> <span id="holdingCount">-</span>
                </div>
                <div class="info-item">
                    <strong>当前时间:</strong> <span id="currentTime">-</span>
                </div>
            </div>
            
            <div style="margin-top: 10px;">
                <div style="display: flex; align-items: center; gap: 10px; flex-wrap: wrap;">
                    <label for="accountSelect">选择账户:</label>
                    <select id="accountSelect" onchange="switchAccount()" >
                        <option value="rich-account">rich-account</option>
                    </select>
                    <button class="btn" onclick="refreshAccountData()">刷新账户数据</button>
                    <input type="text" id="resetBalance" class="price-input" placeholder="重置余额" value="20000" style="width: 120px;">
                    <button class="btn" onclick="resetAccount()">重置账户</button>
                    <input type="text" id="newAccountName" class="price-input" placeholder="新账户名" style="width: 120px;">
                    <input type="text" id="newAccountBalance" class="price-input" placeholder="初始余额" value="10000" style="width: 120px;">
                    <button class="btn" onclick="createAccount()" style="background-color: #28a745;">创建账户</button>
                    <button class="btn" onclick="deleteAccount()" style="background-color: #dc3545;">删除账户</button>
                </div>
            </div>
        </div>

        <div class="card">
                <h3>实时价格市场概览<button class="btn" onclick="refreshMarketData()" style="float: right;">刷新</button></h3>
                <div id="marketOverview">
                    <!-- 市场数据将在此处动态生成 -->
                </div>
        </div>
         <div class="card">
                <h3>AI交易建议 <button class="btn" onclick="refreshAIRecommendations()" style="float: right;">点击AI建议</button></h3>
                <div id="aiRecommendations">
                    <p style="width: 100%;text-align: center;">无，点击Deepseek Ai 给意见</p>
                </div>
       </div>

        <div class="card">
            <h3>当前持仓情况</h3>
            <div id="holdingsTableContainer">
                <table class="market-table" id="holdingsTable">
                    <thead>
                        <tr>
                            <th>币种</th>
                            <th>持仓数量</th>
                            <th>当前价格</th>
                            <th>持仓价值</th>
                            <th>购入成本</th>
                            <th>盈亏情况</th>
                        </tr>
                    </thead>
                    <tbody id="holdingsTableBody">
                        <tr>
                            <td colspan="5" style="text-align: center;">暂无持仓数据</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <div class="card">
            <h3>交易操作</h3>
            <div style="display: flex; align-items: center; gap: 10px; flex-wrap: wrap;">
                    <label for="tradeSymbol">选择币种:</label>
                    <select id="tradeSymbol" style="padding: 8px; border: 1px solid #ddd; border-radius: 4px;">
                        <option value="BTC">Bitcoin (BTC)</option>
                        <option value="ETH">Ethereum (ETH)</option>
                        <option value="BNB">Binance Coin (BNB)</option>
                        <option value="SOL">Solana (SOL)</option>
                        <option value="XRP">Ripple (XRP)</option>
                        <option value="DOGE">Dogecoin (DOGE)</option>
                    </select>
                   <label for="tradeQuantity">交易数量:</label>
                    <input type="number" id="tradeQuantity" min="0" step="0.0001" placeholder="请输入交易数量" class="price-input">
                    <label for="tradeStrategy">交易策略:</label>
                    <select id="tradeStrategy" style="padding: 8px; border: 1px solid #ddd; border-radius: 4px;">
                        <option value="手动交易">手动交易</option>
                        <option value="网格交易">网格交易</option>
                        <option value="趋势跟踪">趋势跟踪</option>
                    </select>
                     <button class="btn btn-buy" onclick="executeBuyTrade()">买入</button>
                    <button class="btn btn-sell" onclick="executeSellTrade()">卖出</button>
            </div>
              <div id="tradeResult" class="trade-result"></div>
        </div>
        <div class="card">
            <h3>账户总价值趋势 <button class="btn" onclick="updateAccountValueChart()" style="float: right;">刷新图表</button></h3>
            <div class="chart-container">
                <canvas id="accountValueChart"></canvas>
            </div>
            <div style="margin-top: 10px; text-align: center;">
                <label for="valueDaysSelect">时间范围:</label>
                <select id="valueDaysSelect" onchange="updateAccountValueChart()">
                    <option value="7">最近7天</option>
                    <option value="30" selected>最近30天</option>
                    <option value="90">最近90天</option>
                </select>
            </div>
        </div>
         <div class="card">
            <h3>价格趋势图</h3>
            <div class="chart-container">
                <canvas id="priceChart"></canvas>
            </div>
            <div>
                <label for="currencySelect">选择币种:</label>
                <select id="currencySelect" onchange="updatePriceChart()">
                    <option value="DOGE">Dogecoin (DOGE)</option>
                    <option value="BTC">Bitcoin (BTC)</option>
                    <option value="ETH">Ethereum (ETH)</option>
                    <option value="BNB">Binance Coin (BNB)</option>
                    <!-- <option value="SOL">Solana (SOL)</option> -->
                    <option value="XRP">Ripple (XRP)</option>
                </select>
                <label for="daysSelect">时间范围:</label>
                <select id="daysSelect" onchange="updatePriceChart()">
                    <option value="7">最近7天</option>
                    <option value="30">最近30天</option>
                    <option value="90">最近90天</option>
                </select>
            </div>
        </div>

        <div class="grid">
            <div class="card">
                <h3>交易历史 <button class="btn" onclick="refreshTradeHistory()" style="float: right;">刷新交易历史</button></h3>
                <div class="trade-history" id="tradeHistory" style="width: 100%;height: 100%;">
                    <div class="trade-item">暂无交易记录</div>
                </div>
                
            </div>

            <div class="card">
                <h3>持仓分布</h3>
                <div class="chart-container">
                    <canvas id="portfolioChart"></canvas>
                </div>
            </div>
        </div>
        
        
    </div>

    <script src="/static/js/main.js"></script>
</body>
</html>